home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / scripts / genprotos.h < prev    next >
Text File  |  1996-09-12  |  3KB  |  135 lines

  1. #NAME */
  2. #     #include <clib/exec_protos.h>
  3. #
  4. #     __AROS_LH3(void, InitStruct,
  5. #
  6. #/*  SYNOPSIS */
  7. #     __AROS_LHA(APTR,  initTable, A1),
  8. #     __AROS_LHA(APTR,  memory,    A2),
  9. #     __AROS_LHA(ULONG, size,      D0),
  10. #
  11. #/*  LOCATION */
  12. #     struct ExecBase *, SysBase, 13, Exec)
  13. #
  14. #
  15. #LP3(void, InitStruct,
  16. #    APTR, initTable, A1,
  17. #    APTR, memory, A2,
  18. #    ULONG, size, D0,
  19. #    struct ExecBase *, SysBase, -13, Exec)
  20. #
  21. ##define InitStruct(initTable, memory, size) \
  22. #__AROS_LC3(void, InitStruct, \
  23. # __AROS_LA(APTR,  initTable, A1), \
  24. # __AROS_LA(APTR,  memory,    A2), \
  25. # __AROS_LA(ULONG, size,      D0), \
  26. #        struct ExecBase *, SysBase, 13, Exec)
  27. #
  28.  
  29. BEGIN {
  30.     indir="include/clib/"
  31.     outdir=indir;
  32.  
  33.     infile=indir tolower(lib) "_protos."
  34.  
  35.     system ("mv " infile "h " infile "bak");
  36.  
  37.     infile=indir tolower(lib) "_protos.bak"
  38.     out=outdir tolower(lib) "_protos.h"
  39.  
  40.     todo=2;
  41.  
  42.     printf ("") > out;
  43.  
  44.     while ((getline < infile) > 0 && todo)
  45.     {
  46.     if ($1 == "Prototypes")
  47.         todo --;
  48.     else if ($1 == "#ifndef" && define=="")
  49.     {
  50.         define = $2;
  51.     }
  52.     else if (todo < 2)
  53.         todo --;
  54.  
  55.     print >> out;
  56.     }
  57. }
  58. /^#?[ \t]*NAME[ \t]*(\*\/)?[ \t]*$/ {
  59.     state=0;
  60.     args=0;
  61.  
  62.     while (getline > 0)
  63.     {
  64.     if (state==0)
  65.     {
  66.         if (match ($0,"^#?[ \t]*__AROS_LH"))
  67.         {
  68.         line=$0;
  69.         sub(/#?[ \t]*$/,"",line);
  70.         match(line,/[a-zA-Z0-9_]+,$/);
  71.         name=substr(line,RSTART,RLENGTH-1);
  72.  
  73.         sub(/^#?[ \t]*/,"",line);
  74.         f=line;
  75.         state=1;
  76.         }
  77.     }
  78.     else if (state == 1)
  79.     {
  80.         if (match ($0,"^#?[ \t]*__AROS_LH"))
  81.         {
  82.         line=$0;
  83.         sub(/[ \t]*$/,"",line);
  84.         sub(/^#?[ \t]*/,"",line);
  85.         f=f "@1" line;
  86.  
  87.         match(line,/,[ \t]*[a-zA-Z0-9_]+[ \t]*,/);
  88.         arg=substr(line,RSTART+1,RLENGTH-2);
  89.         sub(/[ \t]*$/,"",arg);
  90.         sub(/^[ \t]*/,"",arg);
  91.         a[args++] = arg;
  92. #print name ":" arg
  93.         }
  94.         else if (match ($0, /^#?(\/\*)?[ \t]*LOCATION[ \t]*(\*\/)?[ \t]*$/))
  95.         {
  96.         state=2;
  97.         }
  98.     }
  99.     else if (state == 2)
  100.     {
  101.         if ($1 != "")
  102.         {
  103.         line=$0;
  104.         sub(/[ \t]*$/,"",line);
  105.         sub(/^#?[ \t]*/,"",line);
  106.         f=f "@1" line;
  107.         break;
  108.         }
  109.     }
  110.     }
  111.  
  112.     line=f;
  113.     gsub("@1","\n    ",line);
  114.     gsub("__AROS_LH","__AROS_LP",line);
  115.     print line >> out;
  116.  
  117.     printf ("#define %s(", name) >> out;
  118.     for (t=0; t<args; t++)
  119.     {
  120.     printf ("%s", a[t]) >> out;
  121.  
  122.     if (t+1<args)
  123.         printf (", ") >> out;
  124.     }
  125.     printf (") \\\n") >> out
  126.     line=f;
  127.     gsub("@1"," \\\n    ",line);
  128.     gsub("__AROS_LH","__AROS_LC",line);
  129.     print "    " line >> out;
  130.     print "" >> out;
  131. }
  132. END {
  133.     print "\n#endif /* " define " */" >> out
  134. }
  135.